import xlrd
import xlwt

parentPath = r'C:\Users\da\Desktop\\'  # 全局父路径
parentTitle = r'商品名称'  # 第一行商品名称需要去除


def copyValue():
    # 第一步
    # 设置商品分类

    count = 0
    rbook = xlrd.open_workbook(parentPath + '最终售价.xls')
    rbook.sheets()
    rsheet = rbook.sheet_by_index(0)

    rbook2 = xlrd.open_workbook(parentPath + '1.xls')
    rbook2.sheets()
    rsheet2 = rbook2.sheet_by_index(0)

    wbk = xlwt.Workbook()
    sheet = wbk.add_sheet('sheet 1')
    for row in rsheet.get_rows():
        if row[0].value != parentTitle:
            for yuanshi in rsheet2.get_rows():
                if row[0].value == yuanshi[0].value:
                    sheet.write(count, 0, str(yuanshi[0].value))
                    sheet.write(count, 1, str(yuanshi[1].value))
                    sheet.write(count, 2, str(yuanshi[2].value))
                    sheet.write(count, 3, str(yuanshi[3].value))
                    sheet.write(count, 4, str(yuanshi[4].value))
                    sheet.write(count, 5, str(yuanshi[5].value))
                    sheet.write(count, 6, str(yuanshi[6].value))
                    sheet.write(count, 7, str(yuanshi[7].value))
                    sheet.write(count, 8, str(yuanshi[8].value))
                    sheet.write(count, 9, str(yuanshi[9].value))
                    sheet.write(count, 10, str(yuanshi[10].value))
                    sheet.write(count, 11, str(yuanshi[11].value))
                    sheet.write(count, 12, str(yuanshi[12].value))
                    sheet.write(count, 13, str(yuanshi[13].value))
                    sheet.write(count, 14, str(yuanshi[14].value))
                    sheet.write(count, 15, str(yuanshi[15].value))
                    sheet.write(count, 16, str(yuanshi[16].value))
                    sheet.write(count, 17, str(yuanshi[17].value))
                    count = count + 1
                    break
    wbk.save(r'C:\Users\da\Desktop\type.xls')

if __name__ == '__main__':
    copyValue()
